package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.CardInfo;
import com.example.entity.Deposit;
import com.example.mapper.DepositMapper;
import com.example.service.CardInfoService;
import com.example.service.DepositService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

/**
 * 存款类型服务实现类
 */
@Service
public class DepositServiceImpl extends ServiceImpl<DepositMapper, Deposit> implements DepositService {

    @Autowired
    private CardInfoService cardInfoService;

    @Override
    @Transactional
    public boolean removeById(Serializable savingId) {
        // 先删除该存款类型下的所有银行卡
        cardInfoService.remove(
            new QueryWrapper<CardInfo>()
                .eq("saving_id", savingId)
        );
        // 再删除存款类型
        return super.removeById(savingId);
    }
} 